package Injector

import "reflect"

type mapper map[reflect.Type]reflect.Value

func (this mapper) set(v interface{}) {
	if v == nil {
		panic("err")
	}
	if reflect.TypeOf(v).Kind() != reflect.Ptr {
		panic("must ptr")
	}
	this[reflect.TypeOf(v)] = reflect.ValueOf(v)
}
func (this mapper) get(v interface{}) reflect.Value {
	var t reflect.Type
	if bt, ok := v.(reflect.Type); ok {
		t = bt
	} else {
		t = reflect.TypeOf(v)
	}
	if value, ok := this[t]; ok {
		return value
	}
	//处理接口继承
	for k, v := range this {
		if k.Implements(t) {
			return v
		}
	}
	return reflect.Value{}
}
